#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define BUFFER_SIZE 25
#define READ_END 0
#define WRITE_END 1

int main()
{
	char w_msgs[BUFFER_SIZE] = "Greetings !";
	char r_msgs[BUFFER_SIZE];
	int fd[2];
	pid_t pid;
	if (-1 == pipe(fd))
	{
		fprintf(stderr, "Pipe failed !");
		return 1;
	}

	pid = fork();
	if (pid < 0)
	{
		fprintf(stderr, "Fork failed !");
		return 1;
	}
	if (pid > 0)
	{
		// parent process
		close(fd[READ_END]);
		write(fd[WRITE_END], w_msgs, strlen(w_msgs) + 1);
		close(fd[WRITE_END]);
	}
	else
	{
		// child process
		close(fd[WRITE_END]);
		read(fd[READ_END], r_msgs, BUFFER_SIZE);
		close(fd[READ_END]);
		printf("%s\n", r_msgs);
	}

	return 0;
}
